<template>
  <div class="container">
    <div ref="canvas" class="canvas" />
  </div>
</template>

<script>
// 引入相关依赖
import BpmnModeler from 'bpmn-js/lib/Modeler'
import { testBpm } from '@/api/flowable/flowableApi'

export default {
  name: 'Designer',
  data() {
    return {
      bpmnModeler: null, // bpmn 建模器
      container: null,
      canvas: null
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      // 获取canvas的dom节点
      const canvas = this.$refs.canvas
      // 建模
      this.bpmnModeler = new BpmnModeler({
        container: canvas
      })
      this.createNewDiagram()
    },
    createNewDiagram() {
      testBpm().then(rec => {
        const result = this.bpmnModeler.importXML(rec)
        const { warnings } = result
        console.log(warnings)
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    }
  }
}
</script>

<style scoped>
  .container {
    width: 100%;
    height: 100%;
  }
  .canvas {
    width: 100%;
    height: 100%;
  }
</style>
